package mysql

import "gorm.io/gorm"

type Scenic struct {
	gorm.Model
	Name    string `gorm:"type:varchar(100);not null;" json:"name"`
	Address string `gorm:"type:varchar(255);not null;" json:"address"`
}
type Admission struct {
	gorm.Model
	ScenicId   int64   `gorm:"type:int;not null;" json:"scenicId"`
	TicketName string  `gorm:"type:varchar(50);not null;"`
	Price      float64 `gorm:"type:decimal(10,2);not null;"`
	Num        int     `gorm:"type:int;not null;"`
	StartTime  string  `gorm:"type:datetime(3);" json:"startTime"`
}
type Insure struct {
	gorm.Model
	Name  string  `gorm:"type:int;" json:"name"`
	Price float64 `gorm:"decimal(10,2);" json:"price"`
	Types int     `gorm:"int;" json:"types"`
}

func (a *Admission) UpdateNum(id int64, num int) error {
	err := DB.Model(&a).Where("id=?", id).Update("num", num).Error
	if err != nil {
		return err
	}
	return nil
}
func (s *Scenic) FindScenicById(id int64) (scenic []*Scenic, err error) {
	err = DB.Where("id=?", id).Find(&scenic).Error
	if err != nil {
		return nil, err
	}
	return scenic, nil
}
func (a *Admission) FindAdmissionById(id int64) (admission []*Admission, err error) {
	err = DB.Where("scenic_id=?", id).Find(&admission).Error
	if err != nil {
		return nil, err
	}
	return admission, nil

}
func (s *Scenic) FindScenicByIds(id int64) (scenic *Scenic, err error) {
	err = DB.Where("id=?", id).Find(&s).Error
	if err != nil {
		return nil, err
	}
	return s, nil
}
func (a *Admission) FindAdmissionByIds(id int64) (admission *Admission, err error) {
	err = DB.Where("scenic_id=?", id).Find(&a).Error
	if err != nil {
		return nil, err
	}
	return a, nil

}
